
const baseURL = 'http://10.31.71.52:7002'

// 拦截器配置
const httpInterceptor = {
  // 拦截前触发
  invoke(options) {
    // 1. 非 http 开头需拼接地址
    if(!options.url.startsWith('http')){
        options.url = baseURL+options.url
    }
    options.timeout = 10000
    //请求标头
    options.header = {
      ...options.header,
        'source-client': 'miniapp',
    }
  },
}

// 拦截 request 请求
uni.addInterceptor('request', httpInterceptor)
// 拦截 uploadFile 文件上传
uni.addInterceptor('uploadFile', httpInterceptor)

// 请求封装
export const http = (options)=>{
  return new Promise((resolve, reject) => {
    uni.request({
     ...options,
    //  请求成功
    success: function(res) {
      resolve(res)
    },
    })
  })
}